<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{
				
				$taxclass = mysql_real_escape_string($_REQUEST['txclass']);
				$taxprior = mysql_real_escape_string($_REQUEST['taxpriority']);
				$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
				$taxdes = mysql_real_escape_string($_REQUEST['taxdesc']);
			
				
				//$time= date("D: H : i : s : A");
				$insert="INSERT INTO `tbltaxrates`
				(`inttaxclassid` , `inttaxpriority` , `dectaxrate`, `vartaxdesc`)
				VALUES ('$taxclass', '$taxprior', '$taxrat', '$taxdes')";
				$sql=$obj_db->insert($insert);	
				header("location:taxrates.php?msg=add");
				die();
	}	
		

// UPDATE the record

$txclass = "";
$txprior = "";
$txrat = "";
$txdes = "";

$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql = "select * from tbltaxrates where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				//$title1 = $row['vartaxtitle'];	   
		   		//$desc1 = $row['vartaxclassdesc'];
				
				$txclass = $row['inttaxclassid'];
				$taxprior = $row['inttaxpriority'];
				$txrat = $row['dectaxrate'];
				$txdes = $row['vartaxdesc'];
				
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				
				$taxclass = mysql_real_escape_string($_REQUEST['txclass']);
				$taxprior = mysql_real_escape_string($_REQUEST['taxpriority']);
				$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
				$taxdes = mysql_real_escape_string($_REQUEST['taxdesc']);
			$sql_upd ="UPDATE tbltaxrates SET  
						inttaxclassid = '$taxclass',
						inttaxpriority = '$taxprior',
						dectaxrate = '$taxrat',
						vartaxdesc = '$taxdes'					
						 where intid ='$screen_id'";	 
			$result = $obj_db->edit($sql_upd);
			$action=1;
			header("location:taxrates.php?msg=edit");
			die();
		}
	}
}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tbltaxrates` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		header("location:taxrates.php?msg=del");
		die();
	}
}


?>

<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/taxrates.js"></script>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addtaxrates' || trim($_REQUEST['script'])=='edittaxrates')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="taxrates">
		
      <table width="70%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addtaxrates'){echo "Add New Tax Rates...";}
	if($_REQUEST['script']=='edittaxrates'){echo "Edit Tax Rates...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="left">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="29%" align="right" class="sltimg">*Tax Class </td>
          <td width="3%">:</td>
          <td width="57%" align="left"><label>
            <select name="txclass" id="txclass">
<option value="0">None</option>
<?php
$sql="select * from tbltaxclass";
$resman = $obj_db->select($sql);

if(count($resman)>0)
{
	for($m=0;$m<count($resman);$m++)
	{


?>
<option value="<?php echo $resman[$m]['intid'];?>"<?php if($resman[$m]['intid'] == $txclass){echo "selected";}else{echo "";} ?>><?php echo stripslashes($resman[$m]['vartaxtitle']);?></option>
<?php
	}
}
?>
</select>

          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Tax Priority </td>
          <td>:</td>
          <td align="left"><select name="taxpriority" id="taxpriority">
            <option value="0" <?php if($taxprior==0){ echo "Selected";}?>>Select Priority</option>
            <option value="1" <?php if($taxprior==1){ echo "Selected";}?>>Not Compulsory</option>
            <option value="2" <?php if($taxprior==2){ echo "Selected";}?>>Highly Recommend</option>
          </select>          </td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Tax Rate </td>
          <td>:</td>
          <td align="left"><input name="taxrate" type="text" id="taxrate" value="<?php echo stripslashes($txrat);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Tax Description </td>
          <td>:</td>
          <td align="left"><input name="taxdesc" type="text" id="taxdesc" value="<?php echo stripslashes($txdes);?>" /></td>
          <td>&nbsp;</td>
        </tr>

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table></form>
    <?php
	}
}
else
{
?>
<br />
<br />
    <table width="75%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
      <tr class="bg1">
        <td colspan="5" align="left"><strong>Tax Rates...</strong></td>
        <td align="center"><a href="taxrates.php?script=addtaxrates" class="aa">[NEW]</a></td>
      </tr>
      <tr>
         <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="8" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
			</td></form>
        </tr>
      <tr class="tblbg3">
        <td align="center"><strong>Tax Class</strong></td>
		
		<td align="center"><strong>Tax Priority</strong></td>
        <td align="center"><strong>Tax Rate</strong></td>
        <td align="center"><strong>Tax Desc</strong></td>
        <td align="center"><strong>Edit</strong></td>
        <td align="center"><strong>Delete</strong></td>
      </tr>
      <?php
	  
	  
	  
	  /**************************************
		PAGING CODE START
		**************************************/
		if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}
		$tablename="tbltaxrates";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
		PAGING CODE ENDING
		**************************************/
		?>
      <?php
   		$sql="select * from tbltaxrates Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['inttaxclassid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
      <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
        <td align="center">
<?php 		
		
		$sqli="SELECT * FROM `tbltaxclass` WHERE `intid`='$id'";
		//echo $sqli;
		//die();
		$resname = $obj_db->select($sqli);
		if(count($resname)>0)
		{
			for($pn=0;$pn<count($resname);$pn++)
			{
				echo stripslashes($resname[$pn]['vartaxtitle']);
			}
		}
?>		</td>
		<td align="center">
		<?php 
		//if(isset() && isset()!="")
		if($result[$i]['inttaxpriority']=='0')
		{		
			echo "Not Selected";
		}
		if($result[$i]['inttaxpriority']=='1')
		{		
			echo "Not Compulsory";
		}
		if($result[$i]['inttaxpriority']=='2')
		{		
			echo "Highly Recommended";
		}		
		?></td>
		
		<?php //echo $result[$i]['inttaxpriority']; ?>

		<td align="center"><?php echo stripslashes($result[$i]['dectaxrate']);?></td>     
        <td align="center"><?php echo stripslashes($result[$i]['vartaxdesc']);?></td>
        
        
        <td align="center"><a class="link" Title="Click here to Edit" href="taxrates.php?script=edittaxrates&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
        <td align="center"><a Title="Click here to Delete" href="taxrates.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
      </tr>
      <?php }}?>
      <tr>
        <td colspan="6" align="center"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
      </tr>
    </table>
    <?php }?>
	
	</td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">&nbsp;</td>
  </tr>
</table>


